<?php

/**
 * @author PeoneEr
 *  онлайн персонажа
 */
require_once "core/db.php";

class isOnline extends DB {

    private static $_instance = NULL;
    private $_query = NULL;
    private $_fetch = array();

    public static function getInstance() {
        if (is_null(self::$_instance)) {
            $class = __CLASS__;
            self::$_instance = new $class();
        }
        return self::$_instance;
    }

    public function online($nick) {
        /**
         * проверка на онлайн чара
         * @param string $nick
         */
        DB::getInstance()->openConnectionToGS();
        $this->_query = "SELECT `online` FROM `players` WHERE `name` = '$nick' ";
        $this->_fetch = mysql_fetch_assoc(DB::getInstance()->sql($this->_query));
        if ($this->_fetch['online'] == 1) {
            unset($this->_query, $this->_fetch);
            DB::getInstance()->closeConnection();
            return true;
        } else {
            unset($this->_query, $this->_fetch);
            DB::getInstance()->closeConnection();
            return false;
        }
    }

}

?>
